package org.ko.utils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;


public class KOUtils {
	
	private static final String PATTERN = "yyyy-MM-dd";
	
	
	/**
	 * 获取时间的key数组
	 * @param fromDate
	 * @param toDate
	 * @return
	 * @throws ParseException
	 */
	public static List<String> getTimeKey (String fromDate, String toDate) throws Exception {
		if (fromDate.compareTo(toDate) > 0) {
			return null;
		}
		List<String> keys = new ArrayList<String>();
		Calendar calendar = Calendar.getInstance();
		do {
			if (fromDate.equals(toDate)) {
				keys.add(toDate);
				break;
			}
			keys.add(fromDate);
			calendar.setTime(DateUtils.parseDate(fromDate, PATTERN));
			calendar.add(Calendar.DATE, 1);
			fromDate = DateFormatUtils.format(calendar.getTime(), PATTERN);
		} while (true);
		return keys;
	}
	
	private KOUtils() {};
	
}
